#ifndef ASF_DIAG_SUPPORT_DETAILS_TIMER_ENGINE_HPP
#define ASF_DIAG_SUPPORT_DETAILS_TIMER_ENGINE_HPP

#include <memory>
#include <string>

namespace DcAdr
{

    // forward declaration for timer
    class Timer;

    // forward declaration for TimerEnginePrivate
    class TimerEnginePrivate;

    // 定时器引擎，最小堆实现
    // 内部会开启一个线程，Timer超时回调是在此线程中调用的
    class TimerEngine
    {
    public:
        static std::int64_t GetCurrentMillisecs();

    public:
        TimerEngine();
        ~TimerEngine();

        // 添加 Timer， 由 Timer 内部调用， lock决定是否需要加锁
        void AddTimer(Timer *timer, bool lock);
        // 移除 Timer，内部调用，lock决定是否需要加锁
        void RemoveTimer(Timer *timer, bool lock);

    private:
        TimerEngine(const TimerEngine &) = delete;
        TimerEngine &operator=(const TimerEngine &) = delete;

    private:
        std::unique_ptr<TimerEnginePrivate> pri_;
    };

    // 全局引擎
    extern TimerEngine g_global_timer_engine;

} // namespace DcAdr

#endif // ASF_DIAG_SUPPORT_DETAILS_TIMER_ENGINE_HPP